#!/bin/bash

#项目本地svn根目录
SVN_DIRNAME="/data/youbff-pro-code/svn/trunk"

#模块打包文件存放根目录
DST_DIRNAME="/data/youbff-pro-code/deploy"
[ -d $DST_DIRNAME ] || mkdir -p $DST_DIRNAME

#模块文件解压根目录
uncomproess_code_dir="/data/youbff-pro-code/uncomproess-code/"
[ -d $uncomproess_code_dir ] || mkdir -p $uncomproess_code_dir

function foundation()
{
    #框架根工程
    cd $SVN_DIRNAME/core-parent
    mvn clean deploy -Pprd -U
    #原始工程根工程
    cd $SVN_DIRNAME/original-parent
    mvn clean deploy -Pprd -U
    #框架主工程
    cd $SVN_DIRNAME/core-framework-parent
    mvn clean deploy -Pprd -U
    #运营后台dubbo主工程
    cd $SVN_DIRNAME/dubbo-parent
    mvn clean deploy -Pprd -U
    #系统服务主工程
    cd $SVN_DIRNAME/system-parent
    mvn clean deploy -Pprd -U
    #test服务主工程
    cd $SVN_DIRNAME/test-parent
    mvn clean deploy -Pprd -U
    #公共工程
    cd $SVN_DIRNAME/core-framework/core-common
    mvn clean deploy -Pprd -U
    #支付api
    cd $SVN_DIRNAME/system-business/system-business-api
    mvn clean deploy -Pprd -U
}

function YoubffBase(){
    project_base="$1"
    if [ "$project_base" == "system" -o "$project_base" == "pay" -o "$project_base" == "telecom" ];then
        #模块名称
        project_name=${project_base}-business    
        #模块本地svn目录
        project_svn_dir=${SVN_DIRNAME}/${project_name}    
        #模块打包文件
        project_deploy_file=$SVN_DIRNAME/${project_name}/${project_name}-service/target/${project_name}-service-release.zip    
        #模块打包文件解压目录
        project_uncomproess_code=/data/youbff-pro-code/uncomproess-code/${project_name}-service
    elif [ "$project_base" == "dubbo" ];then
        project_name=${project_base}-business
        project_svn_dir=${SVN_DIRNAME}/${project_name}
        project_deploy_file=$SVN_DIRNAME/${project_name}/${project_name}-consume/target/${project_name}-consume-release.zip
        project_uncomproess_code=/data/youbff-pro-code/uncomproess-code/${project_name}-consume
    elif [ "$project_base" == "config" -o "$project_base" == "router" -o "$project_base" == "register-center" ];then
        project_name=${project_base}-business
        project_svn_dir=$SVN_DIRNAME/core-framework/${project_name}
        project_deploy_file=$SVN_DIRNAME/core-framework/${project_name}/target/${project_name}-release.zip
        project_uncomproess_code=/data/youbff-pro-code/uncomproess-code/${project_name}
    fi

    #模块打包
    cd $project_svn_dir
    mvn clean deploy -Pprd -U

    #拷贝模块打包文件到指定目录
    \cp ${project_deploy_file} $DST_DIRNAME

    #删除模块前次解压文件
    [ -d $project_uncomproess_code ] && cd $project_uncomproess_code && rm -rf ./*

    #解压模块打包文件到指定目录
    cd $DST_DIRNAME
    unzip -o `basename ${project_deploy_file}` -d $uncomproess_code_dir    
}


if [ "$#" == "0" ]
then
  foundation
  YoubffBase register-center
  YoubffBase config
  YoubffBase system
  YoubffBase telecom
  YoubffBase pay
  YoubffBase dubbo
  YoubffBase router
elif [ "$#" == "1" ]
then
  case $1 in
  foundation)
    foundation
    ;;
  register-center)
    #注册中心
    YoubffBase register-center
    ;;
    config)
    #配置中心
    YoubffBase config
    ;;
  router)
    #路由中心
    YoubffBase router
    ;;
  system)
    #系统服务
    YoubffBase system
    ;;
  test)
    #test
    YoubffBase test
    ;;
  dubbo)
    #运营服务
    YoubffBase dubbo
    ;;
  *)
    echo "ERROR!Usage:$0 register_center|config|router|system|test|dubbo"
  esac
else
  echo "ERROR!参数不能大于1"
fi